<html>
<head>
    <meta charset="utf-8">
    <title>流程抄送转发</title>
    <#include "/pubHeadStyle.html">
</head>
<body>
    <!--数据列表-->
    <div class="ccpui-tablesize" style="padding: 10px">
        <table lay-filter="processCopyTo" id="processCopyTo" ></table>
    </div>
        <!--查询表单-->
    <script type="text/html" id="headerToolsBar">
        <div class="ccpui-enterSel">
        <div class="layui-btn-container">
            <a class="layui-btn layui-btn-sm" lay-event="query">
                <i class="layui-icon layui-icon-search"></i>
                <span>查询</span>
            </a>
            <a class="layui-btn layui-btn-sm" lay-event="reload">
                <i class="layui-icon layui-icon-refresh"></i>
                <span>重置</span>
            </a>
            <a class="layui-btn layui-btn-sm" lay-event="mark">
                <i class="layui-icon layui-icon-auz"></i>
                <span>标记为已读</span>
            </a>
        </div>
        <form class="layui-form" action="" lay-filter="processCopyToQueryForm" style="margin-top:10px">
            <div class="table-top-filter">
                <div class="table-filter-alone">
                    <label class="layui-form-label">请求标题:</label>
                    <input type="text" name="Q_subject_SL" id="subject" class="layui-input filter-value" placeholder="请求标题"/>
                </div>
                <div class="table-filter-alone">
                    <label class="layui-form-label">发起人:</label>
                    <input type="text" name="Q_creator_SL" id="creator" class="layui-input filter-value" placeholder="发起人"/>
                </div>
                <div class="table-filter-alone">
                    <label class="layui-form-label">类型:</label>
                    <select name="cpType" id="cpType" class="layui-input filter-value">
                        <option value="">全部</option>
                        <option value="1">抄送</option>
                        <option value="2">转发</option>
                    </select>
                </div>
                <div class="table-filter-alone">
                    <label class="layui-form-label">是否已读:</label>
                    <select name="isRead" id="isRead" class="layui-input filter-value">
                        <option value="">全部</option>
                        <option value="1">已读</option>
                        <option value="0">未读</option>
                    </select>
                </div>

                <div class="table-filter-alone">
                    <label class="layui-form-label">创建时间</label>
                    <input type="text" name="Q_beginCcTime_DL" id="beginCcTime" class="layui-input filter-value" placeholder="开始时间"/>
                </div>
                <div class="table-filter-alone">
                    <label class="layui-form-label">至</label>
                    <input type="text" name="Q_endCcTime_DG" id="endCcTime" class="layui-input filter-value" placeholder="结束时间"/>
                </div>
                <div class="table-filter-alone">
                    <label class="layui-form-label">接收时间</label>
                    <input type="text" name="Q_beginReadTime_DL" id="beginReadTime" class="layui-input filter-value" placeholder="开始时间"/>
                </div>
                <div class="table-filter-alone">
                    <label class="layui-form-label">至</label>
                    <input type="text" name="Q_endReadTime_DG" id="endReadTime" class="layui-input filter-value" placeholder="结束时间"/>
                </div>
            </div>
        </form>
        </div>
    </script>
    <script>
        layui.config({
            base: serverPath.systemPath + staticPath.systemPath //静态资源所在路径
        }).extend({
            index: 'index' //主入口模块
        }).use(['index','setter','table','util','commons','common','totalFilter'], function(){
            var setter = layui.setter;
            var table = layui.table;
            var util = layui.util;
            var commons = layui.commons;
            var common = layui.common;
            var $ = layui.$;
            var laydate = layui.laydate;
            var totalFilter = layui.totalFilter;
            var tableH=commons.tabHeight();

            table.render({
                elem: '#processCopyTo'
                ,height:tableH
                ,defaultToolbar: ['filter', 'print']
                ,title:"抄送人"
                ,toolbar: '#headerToolsBar'
                ,method:"post"
                ,page: true
                ,url:serverPath.workflowPath+setter.workflowLinkPath+"processCopyTo/myList?runId=${runId}"
                ,cols: [[
                    {type:'checkbox'}
                    ,{type:'copyId',title:'抄送ID', hide:true}
                    ,{
                        field: 'subject',
                        title: '请求标题',
                        sort: true,
                        minWidth: 330,
                        align: 'center',
                        event: 'detail',
                        style: "cursor:pointer;color:#1E9FFF;text-decoration:underline",
                    }
                    ,{
                            field:'creator',
                        title: '发起人',
                        sort: true,
                        align: 'center',
                        style: "cursor:pointer;color:#1E9FFF;text-decoration:underline",
                        event: 'userInfo'
                    }
                    ,{field:'isRead', title: '是否已读', align: 'center',templet:function (d) {
                        if(d.isRead==0 || d.isRead=='0') {
                            return "<span style='color:red'>未读</span>";
                        }else if(d.isRead==1 || d.isRead=='1'){
                            return "<span style='color:green'>已读</span>";
                        }else{
                            return "";
                        }
                    }}
                    ,{field:'ccTime', title: '创建时间', align: 'center', templet:function (d) {
                            if(d.ccTime){
                                return util.toDateString(d.ccTime, "yyyy-MM-dd HH:mm:ss");
                            }
                            return "";
                        }}
                    ,{field:'ReadTime', title: '接收时间', align: 'center', templet:function (d) {
                            if(d.readTime){
                                return util.toDateString(d.readTime, "yyyy-MM-dd HH:mm:ss");
                            }
                            return "";
                        }}
                    ,{field:'cpType', title: '类型', align: 'center', templet:function (d) {
                            if(d.cpType==1 || d.cpType=='1') {
                                return "<span style='color:green'>抄送</span>";
                            }else if(d.cpType==2 || d.cpType=='2'){
                                return "<span style='color:brown'>转发</span>";
                            }else{
                                return "";
                            }
                        }}
                ]]
                ,done:function () {
                    common.tableSelectCon('.ccpui-enterSel .layui-form input','a[lay-event=query]','.ccpui-enterSel')
                    //渲染时间控件
                    laydate.render({    elem: '#beginCcTime'     });
                    laydate.render({    elem: '#endCcTime'     });
                    laydate.render({    elem: '#beginReadTime'     });
                    laydate.render({    elem: '#endReadTime'     });
                }
            });
        totalFilter.init('processCopyTo');
            //头部监听器
            table.on('toolbar(processCopyTo)', function (obj) {
                switch (obj.event) {
                    case 'query':
                        //查询，不清除查询条件
                        reload(false);
                        break;
                    case 'reload':
                        //重置，并清空查询条件
                        reload(true);
                        break;
                    case 'mark':
                        //标记为已读
                        mark();
                        break;
                }
            });

            table.on('tool(processCopyTo)', function (obj) {
                switch (obj.event) {
                    case 'detail':
                        parent.layer.open({
                            type: 2,
                            title: "流程明细",
                            shade: 0.3,
                            left: 200,
                            area: ['90%', '90%'],
                            content: serverPath.workflowPath + setter.workflowLinkPath + 'processRun/view/info?runId=' + obj.data.runId
                            ,success: function(){
                                //标记为已读
                                if(obj.data.isRead!=1) {
                                    extracted(obj.data.copyId,false);
                                }
                            }
                            ,end: function(){
                                //刷新页面，但不清空查询条件
                                reload(false);
                            }
                        });
                        break;
                    case 'userInfo':
                        layer.open({
                            type: 2,
                            area: ['1000px', '620px'],
                            title: ['查看用户信息'],
                            content:serverPath.systemPath + setter.sysLinkPath +'sysUser/view/view?userId=' + obj.data.createId
                        });
                        break;
                }
            });


            //表格重载
            function reload(isClear) {
                common.tableConditionRender("processCopyTo","processCopyToQueryForm",{where:{}},isClear);
            }
            //标记为已读（获取copyId）
            function mark() {
                var checkStatusData = table.checkStatus('processCopyTo').data;
                if(checkStatusData.length<=0){
                    layer.msg("请至少选择一条有效数据",{icon:5,time:1000})
                    return ;
                }
                var copyIds=[];
                for(var i=0;i<checkStatusData.length;i++){
                    copyIds.push(checkStatusData[i].copyId);
                }
                //执行
                extracted(copyIds.toString(),true);
            }
            //标记为已读（执行操作）
            function extracted(copyIds,isMsg) {
                $.ajax({
                    url: serverPath.workflowPath + setter.workflowLinkPath + "processCopyTo/mark"
                    , method: 'post'
                    , data: {copyIds:copyIds}
                    , dataType: 'json'
                    , success: function (res) {
                        //刷新页面,按照已有查询条件刷新
                        reload(false);
                        //是否弹窗
                        if(isMsg) {
                            //弹窗内容
                            if (commons._filterRecord(res)) {
                                layer.msg(res.msg, {icon: 6, time: 1000})
                            } else {
                                layer.msg(res.msg, {icon: 5, time: 1000})
                            }
                        }
                    }
                })
            }
        });

    </script>
    <style>
        .layui-table-view .layui-form-checkbox[lay-skin=primary] i{
            margin-top: 4px;
        }
    </style>
</body>
</html>